package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.CourseRetakeApplication;
import com.hwadee.teachingprocessmanagementsystem.dao.CourseRetakeApplicationDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.CourseRetakeApplicationService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * (CourseRetakeApplication)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@Service("courseRetakeApplicationService")
public class CourseRetakeApplicationServiceImpl implements CourseRetakeApplicationService {
    @Resource
    private CourseRetakeApplicationDao courseRetakeApplicationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param studentId 主键
     * @return 实例对象
     */
    @Override
    public CourseRetakeApplication queryById(Integer studentId) {
        return this.courseRetakeApplicationDao.queryById(studentId);
    }

    /**
     * 分页查询
     *
     * @param courseRetakeApplication 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CourseRetakeApplication> queryByPage(CourseRetakeApplication courseRetakeApplication, PageRequest pageRequest) {
        long total = this.courseRetakeApplicationDao.count(courseRetakeApplication);
        return new PageImpl<>(this.courseRetakeApplicationDao.queryAllByLimit(courseRetakeApplication, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param courseRetakeApplication 实例对象
     * @return 实例对象
     */
    @Override
    public CourseRetakeApplication insert(CourseRetakeApplication courseRetakeApplication) {
        this.courseRetakeApplicationDao.insert(courseRetakeApplication);
        return courseRetakeApplication;
    }

    /**
     * 修改数据
     *
     * @param courseRetakeApplication 实例对象
     * @return 实例对象
     */
    @Override
    public CourseRetakeApplication update(CourseRetakeApplication courseRetakeApplication) {
        this.courseRetakeApplicationDao.update(courseRetakeApplication);
        return this.queryById(courseRetakeApplication.getStudentId());
    }

    /**
     * 通过主键删除数据
     *
     * @param studentId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer studentId) {
        return this.courseRetakeApplicationDao.deleteById(studentId) > 0;
    }
}
